package com.itheima.group;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;

public class GroupJobMain {
    public static void main(String[] args) throws Exception{
        Job job = Job.getInstance(new Configuration());

        job.setJarByClass(GroupJobMain.class);

        job.setInputFormatClass(TextInputFormat.class);
        TextInputFormat.addInputPath(job,new Path("C:\\Users\\86186\\Desktop\\orders.txt"));

        job.setMapperClass(GroupMapperTask.class);
        job.setMapOutputKeyClass(OrderBean.class);
        job.setMapOutputValueClass(NullWritable.class);

        //分区
        job.setPartitionerClass(MyPartitioner.class);
        //排序：自定义类中已经定义好了
        //规约：
        //分组
        job.setGroupingComparatorClass(MyGroup.class);

        job.setReducerClass(GroupReducerTask.class);
        job.setOutputKeyClass(OrderBean.class);
        job.setOutputValueClass(NullWritable.class);

        job.setOutputFormatClass(TextOutputFormat.class);
        TextOutputFormat.setOutputPath(job,new Path("C:\\Users\\86186\\Desktop\\outputorder2"));

        job.setNumReduceTasks(2);

        boolean flag = job.waitForCompletion(true);
        System.exit(flag?0:1);
    }
}
